<%@page import="tools.MyTool"%>
<%@page import="java.util.Iterator"%>
<%@page import="accessor.HomeProductAccessor"%>
<%@page import="accessor.Products"%>
<%@include file="no_banner_header.jsp" %>
<%
    String key_search = request.getParameter("key_search") != null ? request.getParameter("key_search") :"";
    HomeProductAccessor homeProductAccessor = new HomeProductAccessor();
    List<Products> products = homeProductAccessor.getTopNewProduct(key_search,0);
    String title = key_search==""?"All Products":products.size()>0?"Found "+products.size()+" products for key search : "+key_search+"":"Can not find any products match with : "+key_search;
    int perPage = 10;
    int offSet = request.getParameter("offSet") != null ? Integer.parseInt(request.getParameter("offSet")) : 0;
    int endIndex = offSet + perPage;
    int totalRows = products.size();
    int totalPage = totalRows % perPage == 0 ? totalRows / perPage : totalRows / perPage + 1;
    int pageNo = request.getParameter("pageNo") != null ? Integer.parseInt(request.getParameter("pageNo")) : 1;
    String url = "search_product.jsp?key_search="+key_search;
%>
<div class="content_bar"><%=title%></div>
<div class="break_line"></div>                                                                               
<div class="break_line"></div>                                                                               
<div id="paging" style="float: left;">
    <%=new MyTool().createLinks(url, totalRows, perPage, offSet, pageNo)%>
</div>
<div class="break_line"></div> 
<%for (int i = 0; i < products.size(); i++) {
        if (i >= offSet && i < endIndex) {
            Products product = products.get(i);
%>
<div class="<%=i % 2 == 0 ? "product_item" : "product_item right"%>">
    <%
        MyTool tool = new MyTool();
        String description = tool.getShortDescription(product.getDescription(), 24);
    %>
    <div class="product_item_left">
        <img src="../assets/img/p/<%=product.getDefaultImage()%>" width="128" height="128">
    </div>
    <div class="product_item_right">                            
        <h3><a href="#" title="ac"><%=product.getProductName()%></a></h3>
        <div class="product_item_desc">
            <%=description%>
            <div class="break_line"></div>
            <div class="price">Price: $<%=product.getPrice()%></div>
        </div>

        <a class="button_short" href="#">Add to cart</a>
    </div>
</div>
<%}
    }%>
<div class="break_line"></div>                                                                               
<div id="paging" style="float: right;">
    <%=new MyTool().createLinks(url, totalRows, perPage, offSet, pageNo)%>
</div>
<div style="clear: both;">&nbsp;</div>
<%@include file="footer.jsp" %>